package test;

import java.time.LocalDateTime;
import java.time.Duration;

public class DateTimeExample {
    public static void main(String[] args) {
        LocalDateTime dateTime1 = LocalDateTime.now();
        LocalDateTime dateTime2 = dateTime1.plusHours(3).plusMinutes(30);

        // 计算时间差
        Duration duration1 = Duration.between(dateTime1, dateTime2);

        Duration duration = Duration.parse(""+duration1+"");

        long hours = duration.toHours();
        long minutes = duration.toMinutes() % 60;

        String timeDifference = String.format("用时:%d小时%d分钟", hours, minutes);
        System.out.println(timeDifference);
    }
}